<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script type="text/javascript">
      let dateArr = [
        "2024-06-27",
        "2024-06-21",
        "2024-06-29",
        "2024-06-30",
        "2024-07-01",
      ];
      // 获取当前日期的前几天，或后几天
      const oneDay = 24 * 60 * 60 * 1000;
      const continuousDate = (dateArr = []) => {
        // 排序日期数组
        const sortedDates = [...dateArr].sort(
          (a, b) => new Date(a) - new Date(b)
        );

        // 检查日期是否连续
        for (let i = 0; i < sortedDates.length - 1; i++) {
          const currentDate = new Date(sortedDates[i]);
          const nextDate = new Date(sortedDates[i + 1]);
          //检查是否跨月
          if (
            new Date(currentDate).getMonth() !== new Date(nextDate).getMonth()
          ) {
            let monthNum =
              new Date(nextDate).getMonth() - new Date(currentDate).getMonth();
            console.log("monthNum", monthNum);
            if (monthNum === 1) {
              let currDat = new Date(
                currentDate?.getTime() + oneDay
              ).toISOString();
              let nextDat = nextDate.toISOString();
              if (nextDat == currDat) return true;
            } else {
              console.log("gdfg");
              return false;
            }
          } else {
            // 检查当前日期与下一个日期是否相差一天
            if (
              new Date(currentDate).getDate() !==
              new Date(nextDate).getDate() - 1
            ) {
              return false; // 如果不连续，返回false
            }
          }
        }
        return true; // 如果所有日期都连续，返回true
      };
      
      const continuousThirdDay = (dateArr = []) => {
        // 排序日期数组
        const sortedDates = [...dateArr].sort(
          (a, b) => new Date(a) - new Date(b)
        );
        for (let i = 0; i < sortedDates.length - 2; i++) {
          // 获取当前日期和下两天的日期
          const current = sortedDates[i];
          const nextTwo = sortedDates.slice(i + 1, i + 3);
          // 检查是否有连续的三天
          if (nextTwo.length === 2 && 
              new Date(nextTwo[0]) - new Date(current) === oneDay &&
              new Date(nextTwo[1]) - new Date(nextTwo[0]) === oneDay) {
            return true; // 存在连续三天
          }
       }
  
        return false; // 如果所有日期都连续，返回true
      };
   
      let flag = continuousThirdDay(dateArr);
      console.log(flag);
    </script>
  </body>
</html>
